package com.sea.operate.controller;


import com.codecrane.core.power.service.PowerUserService;
import com.codecrane.core.util.DateUtils;
import com.codecrane.core.util.ExcelUtil;
import com.codecrane.core.web.Ajax;
import com.codecrane.core.web.AjaxReturn;
import com.codecrane.core.web.AjaxTableReturn;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sea.operate.entity.RelatedSku;
import com.sea.operate.entity.RelatedSkuPrice;
import com.sea.operate.entity.RelatedSkuPriceRecord;
import com.sea.operate.service.RelatedSkuPriceRecordService;
import com.sea.operate.service.RelatedSkuPriceService;
import com.sea.operate.service.RelatedSkuService;
import com.sea.product.service.ChannelService;
import com.sea.supply.entity.ProductPriceRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Date;
import java.util.List;


/**
 *  控制器
 * @author 陈鸿飞
 *  <br/>
 *  <br/>
 */
@Controller
@RequestMapping("/sea/operate/relatedSkuPrice/record")
public class RelatedSkuPriceRecordController {

    @Autowired
    private RelatedSkuPriceRecordService relatedSkuPriceRecordService;

    /**
     * 管理主页面
     * @param model
     * @return
     */
    @RequestMapping("/main")
    public String main(Model model,@RequestParam("relatedPriceId")Integer relatedPriceId) {
        model.addAttribute("relatedPriceId",relatedPriceId);
        return "/sea/operate/relatedSkuPrice/record";
    }
    /**
     * 分页条件查询
     *
     * @param pagesize
     * @param start
     * @return
     */
    @ResponseBody
    @RequestMapping("/findByPriceId")
    public AjaxTableReturn findByPriceId(@RequestParam(value = "limit", defaultValue = "10") int pagesize,
                                         @RequestParam(value = "offset", defaultValue = "0") int start,
                                         Integer relatedPriceId
    ) {
        start = start > 0 ? start / pagesize + 1 : 1;
        PageHelper.startPage(start, pagesize);
        List<RelatedSkuPriceRecord> list = relatedSkuPriceRecordService.findByRelatedPriceId(relatedPriceId);
        PageInfo<RelatedSkuPriceRecord> page = new PageInfo<>(list);
        return Ajax.tableDataOk(page.getTotal(), page.getList());
    }

    @ResponseBody
    @RequestMapping("/getHistoryPrice")
    public AjaxReturn getHistoryPrice(@RequestParam("relatedPriceId") Integer relatedPriceId){
        AjaxReturn result = Ajax.fail().setMsg("查询失败！");
        List<RelatedSkuPriceRecord> list = relatedSkuPriceRecordService.findByRelatedPriceId(relatedPriceId);
        if(list.size() > 0){
            result.setOk(true).setData(list);
        }else{
            result.setMsg("暂未查询到商品历史价格!");
        }
        return result;
    }


}
